﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Engine {
    import flash.geom.*;

    public class MathUtil {

        public static function clamp(_arg1:Number, _arg2:Number, _arg3:Number):Number{
            return (Math.min(Math.max(_arg2, _arg1), _arg3));
        }
        public static function wrap(_arg1:Number, _arg2:Number, _arg3:Number=0):Number{
            var _local4:Number = (_arg2 - _arg3);
            while (_arg1 >= _arg2) {
                _arg1 = (_arg1 - _local4);
            };
            while (_arg1 < _arg3) {
                _arg1 = (_arg1 + _local4);
            };
            return (_arg1);
        }
        public static function interpolate(_arg1:Number, _arg2:Number, _arg3:Number):Number{
            return ((((1 - _arg1) * _arg2) + (_arg1 * _arg3)));
        }
        public static function random(_arg1:int, _arg2:int=0):int{
            return ((Math.floor((Math.random() * (_arg1 - _arg2))) + _arg2));
        }
        public static function randomIncl(_arg1:int, _arg2:int):int{
            return ((Math.floor((Math.random() * ((_arg1 - _arg2) + 1))) + _arg2));
        }
        public static function randomEpsilon(_arg1:int, _arg2:int):int{
            return (random((_arg1 + _arg2), (_arg1 - _arg2)));
        }
        public static function randomIndex(_arg1:Array):int{
            return (random(_arg1.length));
        }
        public static function randomElement(_arg1:Array){
            return (((_arg1.length)==0) ? null : _arg1[random(_arg1.length)]);
        }
        public static function randomIndexWeighed(_arg1:Array):int{
            var _local5:Number;
            var _local2:Number = 0;
            var _local3:int;
            while (_local3 < _arg1.length) {
                _local2 = (_local2 + _arg1[_local3]);
                _local3++;
            };
            var _local4:Number = (Math.random() * _local2);
            _local3 = 0;
            while (_local3 < _arg1.length) {
                _local5 = _arg1[_local3];
                if (_local4 < _local5){
                    return (_local3);
                };
                _local4 = (_local4 - _local5);
                _local3++;
            };
            return (-1);
        }
        public static function randomWobble(_arg1:Number, _arg2:Number):Number{
            var _local3:Number = (_arg2 * _arg1);
            return ((_arg1 + (((2 * Math.random()) - 1) * _local3)));
        }
        public static function inEpsilonRange(_arg1:Number, _arg2:Number, _arg3:Number):Boolean{
            return ((Math.abs((_arg1 - _arg2)) < _arg3));
        }
        public static function distance(_arg1:Point, _arg2:Point, _arg3:int=2):Number{
            var _local4:Number = (_arg1.x - _arg2.x);
            var _local5:Number = (_arg1.y - _arg2.y);
            if (_arg3 == 2){
                return (Math.sqrt(((_local4 * _local4) + (_local5 * _local5))));
            };
            if (_arg3 == 1){
                return ((Math.abs(_local4) + Math.abs(_local5)));
            };
            if (_arg3 > 0){
                return (Math.pow((Math.pow(Math.abs(_local4), _arg3) + Math.pow(Math.abs(_local5), _arg3)), (1 / _arg3)));
            };
            return (((_local4)>_local5) ? _local4 : _local5);
        }

    }
}//package Engine 
